<?php
// +----------------------------------------------------------------------
// | YFCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2016 http://www.rainfer.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: rainfer <81818832@qq.com>
// +----------------------------------------------------------------------

namespace app\admin\model;

use think\Model;
use think\Db;

/**
 * 用户数据操作日志模型
 * @package app\admin\model
 */
class UserOperateLog extends Model
{
    /**
     * 构造函数
     */
    public function __construct($name = '', $tablePrefix = '', $connection = '')
    {
        parent::__construct($name, $tablePrefix, $connection);
    }

    /*
    * 添加日志
    * @param  int  case_id 事项编号
    * @param  string  event 事件
    * @return none
    */
    public function addLog($deal_user_id = 0,$type = 0)
    {
        if(!empty($deal_user_id) && !empty($type)){
            $add_log_arr = array(
                'user_id' => intval(session('userinfo.id')),
                'user_name' => trim(session('userinfo.name')),
                'deal_user_id' => $deal_user_id,
                'type' => $type,
                'time' => time()
            );
            $deal_user_info = db('user')->where(array('id'=>$deal_user_id))->find();
            if(is_array($deal_user_info) && !empty($deal_user_info)){
                $add_log_arr['deal_user_name'] = $deal_user_info['user_name'];
            }

            Db::name('user_operate_log')->insert($add_log_arr);
        }
    }

}
